package ipc;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import rddl.RDDL;
import rddl.RDDL.BOOL_EXPR;
import rddl.RDDL.CPF_DEF;
import rddl.RDDL.EXPR;
import rddl.RDDL.LCONST;
import rddl.RDDL.OBJECTS_DEF;
import rddl.RDDL.PVARIABLE_DEF;
import rddl.RDDL.PVAR_INST_DEF;
import rddl.RDDL.PVAR_NAME;
import rddl.RDDL.TYPE_DEF;
import rddl.RDDL.TYPE_NAME;
import rddl.sim.Simulator;


public class IPCState extends rddl.State implements ipc.State {
	
	public IPCState(){
		super();
	}
	
	public HashMap<PVAR_NAME,HashMap<ArrayList<LCONST>,Object>> 
		unwindRewind(HashMap<PVAR_NAME,HashMap<ArrayList<LCONST>,Object>> wrapped){
		HashMap<PVAR_NAME, HashMap<ArrayList<LCONST>, Object>> result 
			= new HashMap<PVAR_NAME,HashMap<ArrayList<LCONST>,Object>>();
		for( PVAR_NAME pvar : wrapped.keySet()){

			HashMap<ArrayList<LCONST>, Object> temp = new HashMap<ArrayList<LCONST>, Object>();
			HashMap<ArrayList<LCONST>, Object> wrappedelem = wrapped.get(pvar); 

			for( ArrayList<LCONST> lcarray : wrappedelem.keySet() ){
				Object val = null ;
				if( wrappedelem.get(lcarray) instanceof Boolean ) 
					val = (Object)(new Boolean((Boolean)wrappedelem.get(lcarray)));
				else if ( wrappedelem.get(lcarray) instanceof Double )
					val = (Object)(new Double((Double)wrappedelem.get(lcarray)));

				
				ArrayList<LCONST> lcarraycpy = new ArrayList<LCONST>();
				for( LCONST lconst : lcarray )
					lcarraycpy.add(new LCONST(lconst._sConstValue));
				
				temp.put(lcarraycpy, val);
			}

			result.put(pvar, temp); 
		}
		return result;
	}
	
	public void copy(rddl.State st) {
		this._state = unwindRewind(st._state);
		this._actions = unwindRewind(st._actions);
		this._interm = unwindRewind(st._interm);
		this._nextState = unwindRewind(st._nextState);
		this._nonfluents = unwindRewind(st._nonfluents);

	}

	public int getAgentTurn() {
		return 0;
	}

	public String toString(){
		return this._state.toString();
	}
	
	@Override
	public int hashCode(){
		return (this._state.hashCode());
	}
	
	@Override
	public boolean equals(Object o){
		return this._state.equals(((IPCState)o)._state); 
	}
}
